package com.marui.mianshi.thread.util;

import java.util.concurrent.*;

/**
 * @author marui
 * @date 2020/4/15 10:05
 * @since 1.0
 */
public class CustomThreadPool {

    public static ThreadPoolExecutor customThreadPool() {
        // 核心线程数
        int coreThreads = 2;
        // 最大线程数
        int maxThreads = 5;
        // 空闲线程存活时间
        long keepAliveTime = 2L;
        // 阻塞队列
        BlockingQueue<Runnable> blockingQueue = new LinkedBlockingQueue<>(3);
        // 拒绝策略
        ThreadPoolExecutor.AbortPolicy rejectPolicy = new ThreadPoolExecutor.AbortPolicy();

        return new ThreadPoolExecutor(coreThreads, maxThreads,
                keepAliveTime, TimeUnit.SECONDS,
                blockingQueue, Executors.defaultThreadFactory(),rejectPolicy);
    }
}
